import { createRouter, createWebHistory } from "vue-router";

const HomePage = () => import("../pages/HomePage.vue");
const CartPage = () => import("../pages/CartPage.vue");
const VerificationPage = () => import("../pages/VerificationPage.vue");
const OrdersPage = () => import("../pages/OrdersPage.vue");
const MemberCenterPage = () => import("../pages/MemberCenterPage.vue");

export const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      name: "home",
      component: HomePage,
      meta: {
        title: "商城首页"
      }
    },
    {
      path: "/cart",
      name: "cart",
      component: CartPage,
      meta: {
        requiresAuth: true,
        title: "购物车"
      }
    },
    {
      path: "/verification",
      name: "verification",
      component: VerificationPage,
      meta: {
        requiresAuth: true,
        title: "库存核实"
      }
    },
    {
      path: "/orders",
      name: "orders",
      component: OrdersPage,
      meta: {
        requiresAuth: true,
        title: "我的订单"
      }
    },
    {
      path: "/member",
      name: "member",
      component: MemberCenterPage,
      meta: {
        requiresAuth: true,
        allowPartial: true,
        title: "会员中心"
      }
    },
    {
      path: "/:pathMatch(.*)*",
      redirect: "/"
    }
  ],
  scrollBehavior() {
    return { top: 0 };
  }
});

export default router;
